package SingletonPattern;

//懒汉式单例类  
public class Singleton2 {

	private static Singleton2 instance;
	
	private Singleton2(){}
	
	//支持并发 但是影响性能  实际上只有第一次使用时需要判断是否为空 其他直接返回
	public static synchronized Singleton2 getInstance(){
		if(instance == null){
			instance = new Singleton2();
		}
		return instance;
	}
	
	public static void main(String[] args) {
		Singleton2 s1 = Singleton2.getInstance();
		Singleton2 s2 = Singleton2.getInstance();
		System.out.println(s1 == s2);
	}

}
